package com.lambert.gingko.watermark.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 文件类型枚举
 * @author lambert
 * @since  2025/08/31
 */
@Getter
@AllArgsConstructor
public enum FileType {
    WORD("word", Arrays.asList("docx", "doc")),
    EXCEL("excel", Arrays.asList("xlsx", "xls")),
    PDF("pdf", Arrays.asList("pdf")),
    IMAGE("image", Arrays.asList("jpg", "jpeg", "png", "bmp", "gif")),
    VIDEO("video", Arrays.asList("mp4", "avi", "mov", "flv", "wmv"));

    /**
     * 处理器类型名称
     */
    private final String typeName;

    /**
     * 支持的文件扩展名
     */
    private final List<String> extensions;

    /**
     * 根据文件扩展名获取对应的FileType
     */
    public static FileType getByExtension(String extension) {
        if (extension == null || extension.isEmpty()) {
            return null;
        }
        
        String ext = extension.toLowerCase();
        for (FileType fileType : values()) {
            if (fileType.getExtensions().contains(ext)) {
                return fileType;
            }
        }
        return null;
    }

    /**
     * 获取所有支持的扩展名
     */
    public static List<String> getAllSupportedExtensions() {
        return Arrays.stream(values())
                .flatMap(type -> type.getExtensions().stream())
                .collect(Collectors.toList());
    }
}
    